package edu.jhu.secondhome.database.beans;

/**
 * Database Bean: Hotel
 */
public class Hotel {
	
	private String hotelName;
	private String description;
	private String address;
	private String phoneNumber;
	private String amenities;
  private String thumbnail;

	public Hotel() { }
	
	public Hotel(String hotelName, String description, String address,
			         String phoneNumber, String amenities, String thumbnail)
	{
		this.hotelName = hotelName;
		this.description = description;
		this.address = address;
		this.phoneNumber = phoneNumber;
		this.amenities = amenities;
		this.thumbnail = thumbnail;
	}

	public String getHotelName() {
		return hotelName;
	}

	public void setHotelName(String hotelName) {
		this.hotelName = hotelName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getAmenities() {
		return amenities;
	}

	public void setAmenities(String amenities) {
		this.amenities = amenities;
	}

	public String getThumbnail()
	{
	  return this.thumbnail;
	}

	public void setThumbnail(String thumbnail)
	{
	  this.thumbnail = thumbnail;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		result = prime * result
				+ ((amenities == null) ? 0 : amenities.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result
				+ ((hotelName == null) ? 0 : hotelName.hashCode());
		result = prime * result
				+ ((phoneNumber == null) ? 0 : phoneNumber.hashCode());
		result = prime * result
		    + ((thumbnail == null) ? 0 : thumbnail.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Hotel other = (Hotel) obj;
		if (address == null) {
			if (other.address != null)
				return false;
		} else if (!address.equals(other.address))
			return false;
		if (amenities == null) {
			if (other.amenities != null)
				return false;
		} else if (!amenities.equals(other.amenities))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (hotelName == null) {
			if (other.hotelName != null)
				return false;
		} else if (!hotelName.equals(other.hotelName))
			return false;
		if (phoneNumber == null) {
			if (other.phoneNumber != null)
				return false;
		} else if (!phoneNumber.equals(other.phoneNumber))
			return false;
		if (thumbnail == null) {
		  if (other.thumbnail != null)
		    return false;
		} else if (!thumbnail.equals(other.thumbnail))
		  return false;
		return true;
	}

	@Override
	public String toString() {
		return "Hotel [hotelName=" + hotelName + ", description=" + description
				+ ", address=" + address + ", phoneNumber=" + phoneNumber
				+ ", amenities=" + amenities + ", thumbnail=" + thumbnail + "]";
	}
	
  /**
   * Accepts a fieldName of the following values:
   * addr1, addr2, addr3, city, state, zip
   * 
   * @param fieldName
   * @return the value of that field or null if no valid fieldName
   *
   */
  public String getAddressSubField( String fieldName )
  {
    if ( address != null )
    {
      String[] fields = address.split( "%%" );
      if ( "addr1".equals( fieldName ) )
      {
        return fields[0].substring( 5 );
      }
      else if ( "addr2".equals( fieldName ) )
      {
        return fields[1].substring( 5 );
      }
      else if ( "addr3".equals( fieldName ) )
      {
        return fields[2].substring( 5 );
      }
      else if ( "city".equals( fieldName ) )
      {
        return fields[3].substring( 4 );
      }
      else if ( "state".equals( fieldName ) )
      {
        return fields[4].substring( 5 );
      }
      else if ( "zip".equals( fieldName ) )
      {
        return fields[5].substring( 3 );
      }
    }
    return null;
  }
}
